<style lang="less">
  @import './login.less';
</style>

<template>
  <div class="login">
    <div class="login-con">
      <Card icon="log-in" title="欢迎登录" :bordered="false">
        <div class="form-con">
          <login-form @on-success-valid="handleSubmit"></login-form>
          <p class="login-tip">输入任意用户名和密码即可</p>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
import LoginForm from '_c/login-form'
import { mapActions } from 'vuex'
export default {
  components: {
    LoginForm
  },
  methods: {
    ...mapActions([
      'handleLogin',
      'getUserInfo'
    ]),
    handleSubmit ({ userName, password }) {
      //调用store中user定义的 handleLogin 方法，并传入 userName和password参数
      this.handleLogin({ userName, password }).then(res => {
        this.getUserInfo().then(res => {
          //路由跳转至首页 /home
          this.$router.push({
            name: this.$config.homeName
          })
        })
      },function () {
        console.log("登录出错误了")
      })
    }
  }
}
</script>

<style>

</style>
